home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / gs261src.zip / gdev3852.c < prev    next >
C/C++ Source or Header  |  1993-05-13  |  6KB  |  188 lines

  1. /* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /*
  20. This driver program created by Kevin M. Gift <kgift@draper.com> in Sept. 1992.
  21. Modified 3/93 to correct bug in cnt_2prn size.
  22. Modified 3/93 to dimension page back to 8.5, which seems to
  23.    work better than the actual page width of 7.6, ie. it uses
  24.     the full printing width of the printer.
  25.     It was modeled after the V2.4.1 HP Paintjet driver (gdevpjet.c) */
  26.  
  27. /* gdev3852.c */
  28. /* IBM 3852 JetPrinter color ink jet driver for Ghostscript */
  29.  
  30. #include "gdevprn.h"
  31. #include "gdevpcl.h"
  32.  
  33. /* X_DPI and Y_DPI must be the same - use the maximum graphics resolution */
  34. /*   for this printer  */
  35. #define X_DPI 84
  36. #define Y_DPI 84
  37.  
  38. /* We round up LINE_SIZE to a multiple of 8 bytes */
  39. /* because that's the unit of transposition from pixels to planes. */
  40. /* Should = 96 (KMG) */
  41. #define LINE_SIZE ((X_DPI * 86 / 10 + 63) / 64 * 8)
  42.  
  43. /* The device descriptor */
  44. private dev_proc_print_page(jetp3852_print_page);
  45. private gx_device_procs jetp3852_procs =
  46.   prn_color_procs(gdev_prn_open, gdev_prn_output_page, gdev_prn_close,
  47.     gdev_pcl_3bit_map_rgb_color, gdev_pcl_3bit_map_color_rgb);
  48. gx_device_printer gs_jetp3852_device =
  49.   prn_device(jetp3852_procs, "jetp3852",
  50.     86,                /* width_10ths, 8.6" (?) */
  51.     110,                /* height_10ths, 11" */
  52.     X_DPI, Y_DPI,
  53.     0.0, 0, 0.0, 0,        /* left, bottom, right, top margins */
  54.     3, jetp3852_print_page);
  55.  
  56.  
  57. /* ------ Internal routines ------ */
  58.  
  59. /* Send the page to the printer.  */
  60. private int
  61. jetp3852_print_page(gx_device_printer *pdev, FILE *prn_stream)
  62. {
  63. #define DATA_SIZE (LINE_SIZE * 8)
  64.  
  65.    unsigned int cnt_2prn;
  66.     unsigned int count,tempcnt;
  67.     unsigned char vtp,cntc1,cntc2;
  68.     int line_size_color_plane;
  69.  
  70.     byte data[DATA_SIZE];
  71.      byte plane_data[LINE_SIZE * 3];
  72.  
  73.     /* Set initial condition for printer */
  74.     fputs("\033@",prn_stream);
  75.  
  76.     /* Send each scan line in turn */
  77.        {    int lnum;
  78.         int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  79.         int num_blank_lines = 0;
  80.         for ( lnum = 0; lnum < pdev->height; lnum++ )
  81.            {    byte _ss *end_data = data + line_size;
  82.             gdev_prn_copy_scan_lines(pdev, lnum,
  83.                          (byte *)data, line_size);
  84.             /* Remove trailing 0s. */
  85.             while ( end_data > data && end_data[-1] == 0 )
  86.                 end_data--;
  87.             if ( end_data == data )
  88.                {    /* Blank line */
  89.                 num_blank_lines++;
  90.                }
  91.             else
  92.                {    int i;
  93.                 byte _ss *odp;
  94.                 byte _ss *row;
  95.  
  96.                 /* Pad with 0s to fill out the last */
  97.                 /* block of 8 bytes. */
  98.                 memset(end_data, 0, 7);
  99.  
  100.                 /* Transpose the data to get pixel planes. */
  101.                 for ( i = 0, odp = plane_data; i < DATA_SIZE;
  102.                       i += 8, odp++
  103.                     )
  104.                  { /* The following is for 16-bit machines */
  105. #define spread3(c)\
  106.  { 0, c, c*0x100, c*0x101, c*0x10000L, c*0x10001L, c*0x10100L, c*0x10101L }
  107.                    static ulong spr40[8] = spread3(0x40);
  108.                    static ulong spr8[8] = spread3(8);
  109.                    static ulong spr2[8] = spread3(2);
  110.                    register byte _ss *dp = data + i;
  111.                    register ulong pword =
  112.                      (spr40[dp[0]] << 1) +
  113.                      (spr40[dp[1]]) +
  114.                      (spr40[dp[2]] >> 1) +
  115.                      (spr8[dp[3]] << 1) +
  116.                      (spr8[dp[4]]) +
  117.                      (spr8[dp[5]] >> 1) +
  118.                      (spr2[dp[6]]) +
  119.                      (spr2[dp[7]] >> 1);
  120.                    odp[0] = (byte)(pword >> 16);
  121.                    odp[LINE_SIZE] = (byte)(pword >> 8);
  122.                    odp[LINE_SIZE*2] = (byte)(pword);
  123.                  }
  124.                 /* Skip blank lines if any */
  125.                 if ( num_blank_lines > 0 )
  126.                    {    
  127.                     if (lnum == 0) 
  128.                       { /* Skip down the page from the top */
  129.                           /* set line spacing = 1/8 inch */
  130.                        fputs("\0330",prn_stream);
  131.                        /* Set vertical tab */
  132.                          vtp = (num_blank_lines  / 8);
  133.                         fprintf(prn_stream,"\033B%c\000",vtp);
  134.                         /* Do vertical tab */
  135.                         fputs("\013",prn_stream);
  136.                         num_blank_lines = 0;
  137.                         }
  138.                      else
  139.                        { /* Do "dot skips" */
  140.                         while(num_blank_lines > 255)
  141.                           {
  142.                           fputs("\033e\377",prn_stream);
  143.                           num_blank_lines -= 255;
  144.                           }
  145.                         vtp = num_blank_lines; 
  146.                         fprintf(prn_stream,"\033e%c",vtp);
  147.                         num_blank_lines = 0;
  148.                      }
  149.                    }
  150.  
  151.                 /* Transfer raster graphics in the order R, G, B. */
  152.                 /* Apparently it is stored in B, G, R */
  153.                 /* Calculate the amount of data to send by what */
  154.                 /* Ghostscript tells us the scan line_size in (bytes) */
  155.  
  156.                 count = line_size / 3;
  157.                 line_size_color_plane = count / 3;
  158.                cnt_2prn = line_size_color_plane * 3 + 5;
  159.                 tempcnt = cnt_2prn;
  160.                 cntc1 = (tempcnt & 0xFF00) >> 8;
  161.                 cntc2 = (tempcnt & 0x00FF);
  162.                 fprintf(prn_stream, "\033[O%c%c\200\037",cntc2,cntc1);
  163.                 fputc('\000',prn_stream);
  164.                fputs("\124\124",prn_stream);
  165.  
  166.                 for ( row = plane_data + LINE_SIZE * 2, i = 0; 
  167.                       i < 3; row -= LINE_SIZE, i++ )     
  168.                 {    int jj;
  169.                    byte ctemp;
  170.                    odp = row;
  171.                     /* Complement bytes */
  172.                     for (jj=0; jj< line_size_color_plane; jj++)
  173.                       { ctemp = *odp;
  174.                         *odp++ = ~ctemp;
  175.                          }
  176.                     fwrite(row, sizeof(byte),
  177.                         line_size_color_plane, prn_stream);
  178.                     }
  179.                }
  180.            }
  181.        }
  182.  
  183.     /* eject page */
  184.      fputs("\014", prn_stream);  
  185.  
  186.     return 0;
  187. }
  188.